package edu.isistan.matching.utils.serviceMatching;

import edu.isistan.matching.adapters.AdapterFactory;
import edu.isistan.matching.adapters.PrimitiveTypeAdapter;
import edu.isistan.metamodel.DataType;
import edu.isistan.metamodel.Operation;

public class StructureMatching extends AbstractMatching {

	public StructureMatching() {
		super();
		setOperationMessagesWeigth(1);
		setOperationNamesWeigth(0);
	}
	
	@Override
	public double analyzeOperationMatching(Operation op1, Operation op2) {
		return MINSCORE;
	}

	@Override
	public double analyzePrimitivesMatching(DataType tipo1, DataType tipo2) {		
		return matchPrimitiveTypes(tipo1, tipo2);
	}

	protected double matchPrimitiveTypes(DataType tipo1, DataType tipo2) {
		getLogger().debug("MATCH PRIMITIVE TYPES");
		PrimitiveTypeAdapter adapter = AdapterFactory.getAdapter(tipo1);
		getLogger().debug("ADAPTADOR: " + adapter.getClass());
		getLogger().debug("TYPE1: " + tipo1.getType());
		getLogger().debug("TYPE2: " + tipo2.getType());
		boolean sinPerdida = adapter.isFullyCompatible(tipo2);		
		if (sinPerdida) {
			getLogger().debug("SIN PERDIDA: " + sinPerdida);
			return MAXSCORE;
		} else {
			boolean conPerdida = adapter.isLoosyCompatible(tipo2);			
			if (conPerdida) {
				getLogger().debug("CON PERDIDA: " + conPerdida);
				return MEDIUM_SCORE;
			}
		}
		getLogger().debug("INCOMPATIBLE: true");
		return MINSCORE;
	}
}
